<?php
class Group extends Eloquent {

    /**
     * Specifies which attributes should be mass-assignable
     * @var array
     */
    protected $fillable = array('name');
    
    /**
     * Specifies which attributes should be valid for create|edit
     * 
     * @param number $id
     * @return multitype:string
     */
    public static function rules($id = 0) 
    {
    	return array(
    		'name' => 'required|unique:groups,name' . ($id ? ",$id" : '')
    	);
    }
    
    /**
     * A group with many resources, where the resources are also shared by other groups.
     *
     * @return void
     */
    public function resources()
    {
        return $this->belongsToMany('Resource');
    }

    /**
     * A group with many users, where the users are also shared by other groups.
     *
     * @return void
     */
    public function users()
    {
        return $this->belongsToMany('User');
    }
}